package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.ExpendItem;
import cn.wolfcode.crm.mapper.ExpendItemMapper;
import cn.wolfcode.crm.query.ExpendItemQuery;
import cn.wolfcode.crm.service.IExpendItemService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

@Service
public class ExpendItemServiceImpl implements IExpendItemService {

    @Autowired
    ExpendItemMapper mapper;

    @Override
    public int insert(ExpendItem record) {
        return mapper.insert(record);
    }

    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public ExpendItem selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ExpendItem> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(ExpendItem record) {
        return mapper.updateByPrimaryKey(record);
    }


    @Override
    public PageResult query(ExpendItemQuery qo) {
        List<ExpendItem> expendItems = mapper.queryList(qo);
        System.out.println(mapper.queryList(qo).get(0).getAmount());
        //查询总数
        int count = mapper.queryCount(qo);
        //如果总数>1就查询结果集
        if(count>0){
            return new PageResult(count,mapper.queryList(qo));
        }
        return new PageResult(0, Collections.EMPTY_LIST);
    }

    public BigDecimal selectTotalAmount() {
        return mapper.selectTotalAmount();
    }
}
